/*
 * $Id$
 *
 *
 * UMKC Robotics 2009
 *
**/


#include "mega128_io.h"

/* control objects for all peripherals are declared / instantiated
 * within their respective .h and .c files.
**/
extern const ButtonController buttonctl; 
extern const LCDController lcdctl;

/* instantiate the bioctl object. */
const BotIOController bioctl = {

  m128_io_ctl

};


/* function that dispatches IO operations on a 'channel' */
void m128_io_ctl(BotIOIdx chan, BotIOCmd cmd) {

  switch(cmd) {

	case io_init:		/* INIT Routines */

		switch(chan) {

			case io_channel_00:	/*button 1*/
			case io_channel_01:	/*button 2*/
			case io_channel_02:	/*button 3*/
			case io_channel_03:	/*button 4*/
			case io_channel_04:	/*button 5*/
				buttonctl.init();
				break;

			case io_channel_05:	/*LCD 0*/	
			case io_channel_06:	/*LCD 1*/	
			case io_channel_07:	/*LCD 2*/	
			case io_channel_08:	/*LCD 3*/	
			case io_channel_09:	/*LCD 4*/	
			case io_channel_10:	/*LCD 5*/	
			case io_channel_11:	/*LCD 6*/	
			case io_channel_12:	/*LCD 7*/	
				lcdctl.init();
				break;
			
			default: break;
		}
	
		break;

	case io_disable:	/* DISABLE Routines */

                switch(chan) {

                        case io_channel_00:     /*button 1*/
                        case io_channel_01:     /*button 2*/
                        case io_channel_02:     /*button 3*/
                        case io_channel_03:     /*button 4*/
                        case io_channel_04:     /*button 5*/
                                buttonctl.disable();
                                break;

                        case io_channel_05:     /*LCD 0*/
                        case io_channel_06:     /*LCD 1*/
                        case io_channel_07:     /*LCD 2*/
                        case io_channel_08:     /*LCD 3*/
                        case io_channel_09:     /*LCD 4*/
                        case io_channel_10:     /*LCD 5*/
                        case io_channel_11:     /*LCD 6*/
                        case io_channel_12:     /*LCD 7*/
                                lcdctl.disable();
                                break;

                        default: break;
                }

                break;

	case io_reset:		/* RESET Routines */

                switch(chan) {

                        case io_channel_00:     /*button 1*/
                        case io_channel_01:     /*button 2*/
                        case io_channel_02:     /*button 3*/
                        case io_channel_03:     /*button 4*/
                        case io_channel_04:     /*button 5*/
                                buttonctl.disable();
                                buttonctl.enable();
                                break;

                        case io_channel_05:     /*LCD 0*/
                        case io_channel_06:     /*LCD 1*/
                        case io_channel_07:     /*LCD 2*/
                        case io_channel_08:     /*LCD 3*/
                        case io_channel_09:     /*LCD 4*/
                        case io_channel_10:     /*LCD 5*/
                        case io_channel_11:     /*LCD 6*/
                        case io_channel_12:     /*LCD 7*/
                                lcdctl.disable();
                                lcdctl.enable();
                                break;

                        default: break;
                }

                break;


	case io_clear:		/* CLEAR (soft reset) Routines */

                switch(chan) {

                        case io_channel_00:     /*button 1*/
                        case io_channel_01:     /*button 2*/
                        case io_channel_02:     /*button 3*/
                        case io_channel_03:     /*button 4*/
                        case io_channel_04:     /*button 5*/
                                break;

                        case io_channel_05:     /*LCD 0*/
                        case io_channel_06:     /*LCD 1*/
                        case io_channel_07:     /*LCD 2*/
                        case io_channel_08:     /*LCD 3*/
                        case io_channel_09:     /*LCD 4*/
                        case io_channel_10:     /*LCD 5*/
                        case io_channel_11:     /*LCD 6*/
                        case io_channel_12:     /*LCD 7*/
                                lcdctl.clear();
                                break;

                        default: break;
                }

                break;

	case io_read: 		/* READ Routines - finish me */
	case io_write: 		/* WRITE Routines - finish me */

        default:	/* error */
		break

  }	/* end top level switch */

}	/* end m128_ioctl() */

